package datamodel.entities;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import datamodel.world.Realm;

/**
 * responsible for the base attributes and functions for all game entities
 * @author Peter
 *
 */
public abstract class Entity {
	
	/**
	 * tracks the entity's realm affinity. values for the hash map are restricted to 
	 * the numbers 0 through 7
	 */
	HashMap<Realm, Integer> realmAffinity;
	
	/**
	 * default constructor that fills the entity with default realm affinity values
	 */
	Entity(){
		this.realmAffinity = new HashMap<Realm, Integer>(5);
		realmAffinity.put(Realm.ARTIFICE,  0);
		realmAffinity.put(Realm.ELEMENTAL, 0);
		realmAffinity.put(Realm.MYSTICISM, 0);
		realmAffinity.put(Realm.NAMER, 0);
		realmAffinity.put(Realm.WILD, 0);
	}
	
	/**
	 * constructor that fills the entity with given realm affinity values
	 * @param rA is the map of realms and affinity values 
	 */
	Entity(HashMap<Realm, Integer> rA){
		for(Realm r: rA.keySet()){
			if(rA.get(r) > 7 || rA.get(r) < 0){
				throw new IllegalArgumentException("Entity given bad realm affinity value for the " + r.toString() + "realm");
			}
		}
		this.realmAffinity = rA;
	}
	
	/**
	 * retrieves a list of the realms that this entity belongs to 
	 * @return a list of the realms that this entity belongs to 
	 */
	public List<Realm> activeRealms(){
		LinkedList<Realm> activeRealms = new LinkedList<Realm>();
		for (Realm r : realmAffinity.keySet()){
			if(realmAffinity.get(r) > 0){
				activeRealms.add(r);
			}
		}
		return activeRealms;
	}
	
	/**
	 * Responsible for dumping the attributes and stats of the entity to a file
	 * @param filename is the file name to which the entity was saved
	 */
	public abstract void dumpToFile(String filename);
	
	
	
	

}
